package com.example.demo.controller;
import com.example.demo.service.Tencent_SpeechService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.Date;

@RestController
@Api(tags = "语音识别和智能闲聊(语音识别小程序难接入)")
public class SpeechController {
    @Autowired
    private Tencent_SpeechService tencent_speechService;
    @PostMapping("/getVoiceToText")
    @ApiOperation("语音识别")
    public String getOcr_(@ApiParam("提交需要识别的声音文件<br>Tips:微信小程序的是假的SILK格式")
                          @RequestParam("file")MultipartFile file,
                          @ApiParam("语音压缩格式编码:<br>1 ->PCM <br>2 ->WAV <br>3 ->AMR <br>4 ->SILK")
                          @RequestParam("format")String format,
                          @ApiParam("语音采样率编码:<br>8000 ->8KHz <br>16000 ->16KHz ")
                          @RequestParam("rate")String rate,
                          @ApiParam("用户openid,可提交可不提交，不提交则不会保存") @RequestParam(value = "openid",defaultValue = "undefined") String openid)throws Exception {
        String result = tencent_speechService.getVoiceToText(file.getBytes(),format,rate);
        return result;
    }
    @PostMapping("/getAIToText")
    @ApiOperation("智能闲聊")
    public String getOcr_(@ApiParam("向人工智障提出你想问的问题")
                            @RequestParam("question")String  question,
                          @ApiParam("这个是你的id，通过这个session让机器人知道你是哪个用户。")
                          @RequestParam("session")String session,
                          @ApiParam("用户openid,可提交可不提交，不提交则不会保存") @RequestParam(value = "openid",defaultValue = "undefined") String openid)throws Exception {
        String result = tencent_speechService.getAIToText(question,session);
        return result;
    }
}
